/**
 * 软件著作权：东方汇创
 *
 * 系统名称：  xxx项目
 *
 * 文件名称：  PriceController.java
 *
 * 功能描述：  价格管理Controller
 * 
 * 版本历史：
 * 
 * 2017-07-28   1.0.0版 （龙色波）（创建文件）
 */

package com.dfhc.base.price.web;



import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.quickbundle.base.web.page.RmPageVo;
import org.quickbundle.project.RmGlobalReference;
import org.quickbundle.project.RmProjectHelper;
import org.quickbundle.tools.helper.RmJspHelper;
import org.quickbundle.tools.helper.RmVoHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.alibaba.fastjson.JSONObject;
import com.dfhc.ISystemConstant;
import com.dfhc.PjException;
import com.dfhc.base.price.IPriceConstants;
import com.dfhc.base.price.service.PriceService;
import com.dfhc.base.price.vo.PriceVo;
import com.dfhc.pub.concurrencycontrol.RequestConcurrentRoute;
import com.dfhc.pub.service.ExcelService;
import com.dfhc.util.FileOperateHelper;
import com.dfhc.util.StringHelper;

/**
 * 价格管理 Controller
 * 
 * @author 龙色波
 * @see 参见的类
 */
@Controller
@RequestMapping(value = "/price")
public class PriceController implements IPriceConstants {

    @Autowired
    /**
     * 价格管理服务
     */
    private PriceService priceService;
    
    /**
     * 简单查询，分页显示，支持表单回写
     * @param model 模型
     * @param request http请求对象
     * @return 跳转的列表jsp     
     */
    @RequestMapping(value = "")
    public String list(Model model, HttpServletRequest request) {
	model.addAttribute(ISystemConstant.QUERY_STRING, request.getQueryString());//全部参数
        model.addAttribute(ISystemConstant.RM_PARENT_CODE, request.getParameter(ISystemConstant.RM_PARENT_CODE));  //把模块代码放入request     
        return "/qb5activiti/base/price/listPrice";
    }
   
    /**
     * ajax 请求列表数据
     * @param model
     * @param request
     * @return
     * @throws IOException 
     */
    @RequestMapping(value = "ajaxList")
    public void ajaxList(Model model, HttpServletRequest request, HttpServletResponse response) throws IOException{
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

	        Map<String,Object> dataMap=new HashMap<String,Object>();
        
	        String page=request.getParameter("page")==null?"1":request.getParameter("page");
	        String rows=request.getParameter("rows")==null?ISystemConstant.DEFAULT_PAGE_SIZE:request.getParameter("rows");
	        int rowsInt=Integer.parseInt(rows);//页大小
	        int pageInt=Integer.parseInt(page);//当前页
	        Map<String, Object> searchPara = getQueryCondition(request);  //从request中获得查询条件
	        RmPageVo pageVo = RmJspHelper.transctPageVo(request, priceService.getCount(searchPara));
	        pageVo.setPageSize(rowsInt);
	        pageVo.setCurrentPage(pageInt);
	        String orderStr = RmJspHelper.getOrderStr(request);  //得到排序信息
        	if(StringHelper.isEmpty(orderStr)){
	            String sidx=request.getParameter("sidx")==null?"id":request.getParameter("sidx");
            	    String sord=request.getParameter("sord")==null?"desc":request.getParameter("sord");
        	    orderStr=sidx+" "+sord;
	        }
        
        	List<PriceVo> beans = priceService.list(searchPara, orderStr, pageVo.getStartIndex(), pageVo.getPageSize());  //按条件查询全部,带排序
        	//翻译状态码
        	if(beans!=null){
	        	for(PriceVo bean:beans){
				//如果状态码字段有其他用途，请用扩展字段attribute1-attribute5代替
	        		bean.setStatus(RmGlobalReference.get(ISystemConstant.DICTIONARY_PRICE_STATUS, bean.getStatus()));
	        	}
        	}         
	        dataMap.put("page",  pageVo.getCurrentPage());
        	dataMap.put("total",  pageVo.getPageCount());
	        dataMap.put("records",  pageVo.getRecordCount());
        	dataMap.put("rows", beans);
         
	        response.setCharacterEncoding("UTF-8"); 
        	response.getWriter().write(JSONObject.toJSONString(dataMap));
          }finally{
	        //最后解锁
	        RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    
    /**
     * 从页面表单获取信息注入vo，并插入单条记录
     * @param request http请求对象
     * @param vo 值对象
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "insert", method = RequestMethod.POST, 
			consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> insert(HttpServletRequest request, @Valid PriceVo vo) {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
	        RmVoHelper.markCreateStamp(request,vo);  //打创建时间,IP戳
//        	priceService.insert(vo);  //插入单条记录
	        String userId = RmProjectHelper.getRmUserId(request);
	        Map<String, Object>  variables = new HashMap<String,Object>();
	        try {
				priceService.doStartWorkflow(vo, userId, variables);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	        Map<String, Object> result = new HashMap<String, Object>();
        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
	        result.put(ISystemConstant.AJAX_MESSAGE, "新增成功: " + vo.getId());
        	return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    
    /**
     * 从页面表单获取信息注入vo，并修改单条记录
     * @param request 请求对象
     * @param vo 值对象
     * @param errors Ajax错误对象
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "update", method = RequestMethod.POST, 
			consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> update(HttpServletRequest request, @Valid PriceVo vo) {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
        	RmVoHelper.markModifyStamp(request,vo);  //打修改时间,IP戳
	        priceService.update(vo);  //更新单条记录
        	Map<String, Object> result = new HashMap<String, Object>();
	        result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
        	result.put(ISystemConstant.AJAX_MESSAGE, "修改成功: " + vo.getId());
	        return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * 根据id获取单条记录
     * @param request 请求对象
     * @param vo 值对象
     * @param
     * @return 返回Ajax应答实体对象
     */
    @RequestMapping(value = "get/{id}/{dateTime}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String,Object> get(@PathVariable("id") String id, HttpServletRequest request) {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
        	PriceVo bean = priceService.get(id);
	        Map<String, Object> result = new HashMap<String, Object>();
        	if(bean==null){
	            result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
        	    result.put(ISystemConstant.AJAX_MESSAGE, "记录没找到(id:"+id+")!");
	            return result;
        	}
        
	        result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
        	result.put(ISystemConstant.AJAX_BEAN, bean);
	        return result;			
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }    
    /**
     * 从页面的表单获取单条记录id并删除，如request.id为空则删除多条记录（request.ids）
     * @param request http请求对象
     * @param redirectAttributes 重定向属性
     * @return 返回列表页面
     */
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public String delete(HttpServletRequest request, RedirectAttributes redirectAttributes) {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

        	int deleteCount = 0;  //定义成功删除的记录数
	        String id = request.getParameter(REQUEST_ID);
        	if(id != null && id.length() > 0) {
	            deleteCount = priceService.delete(id);
	        } else {
        	    String[] ids = RmJspHelper.getArrayFromRequest(request, REQUEST_IDS); //从request获取多条记录id
	            if (ids != null && ids.length != 0) {
        	        deleteCount += priceService.delete(ids);  //删除多条记录
	            }
        	}
	        redirectAttributes.addFlashAttribute("message", "删除成功: " + deleteCount);
        	return "redirect:/price?"+ISystemConstant.RM_PARENT_CODE+"="+request.getParameter(ISystemConstant.RM_PARENT_CODE);
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
   /**
     * 从页面的表单获取单条记录id并逻辑删除，如request.id为空则删除多条记录（request.ids）
     * @param request http请求对象
     * @param redirectAttributes 重定向属性
     * @return 返回列表页面
     */
    @RequestMapping(value = "logicDelete", method = RequestMethod.POST)
    public String deleteLogic(HttpServletRequest request, RedirectAttributes redirectAttributes) {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));
        	int deleteCount = 0;  //定义成功删除的记录数
	        String id = request.getParameter(REQUEST_ID);
        	if(id != null && id.length() > 0) {
	            deleteCount = priceService.deleteLogic(request,id);
        	} else {
	            String[] ids = RmJspHelper.getArrayFromRequest(request, REQUEST_IDS); //从request获取多条记录id
        	    if (ids != null && ids.length != 0) {
                	deleteCount += priceService.deleteLogic(request,ids);  //删除多条记录
	            }
        	}
	        redirectAttributes.addFlashAttribute("message", "删除成功: " + deleteCount);
        	return "redirect:/price?"+ISystemConstant.RM_PARENT_CODE+"="+request.getParameter(ISystemConstant.RM_PARENT_CODE);
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * 从页面的表单获取单条记录id，并察看这条记录的详细信息
     * @param id 待删除的id
     * @param model 模型
     * @request 请求对象
     * @return 返回详细信息页面
     */
    @RequestMapping(value = "detail/{id}")
    public String detail(@PathVariable("id") String id, Model model, HttpServletRequest request) {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

	        PriceVo bean = priceService.get(id);
	        model.addAttribute(REQUEST_BEAN, bean);  //把vo放入request
        	if(RM_YES.equals(request.getParameter(REQUEST_IS_READ_ONLY))) {
	            model.addAttribute(REQUEST_IS_READ_ONLY, request.getParameter(REQUEST_IS_READ_ONLY));
        	}
	        return "/qb5activiti/base/price/detailPrice";
          }finally{
    	    //最后解锁
    	    RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }

    /**
     * 参照信息查询，带简单查询，分页显示，支持表单回写
     * @param model 模型
     * @param request http请求对象
     * @return 返回参照列表页面
     */
    @RequestMapping(value = "reference")
    public String reference(Model model, HttpServletRequest request) {
    	model.addAttribute(ISystemConstant.QUERY_STRING, request.getQueryString());//全部参数
        model.addAttribute(REQUEST_REFERENCE_INPUT_TYPE, request.getParameter(REQUEST_REFERENCE_INPUT_TYPE));  //传送输入方式,checkbox或radio
        return "/qb5activiti/base/price/util/referencePrice";
    }
    /**
     * 参照改为ajax
     * @param model
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "referenceAjax")
    public void referenceAjax(Model model, HttpServletRequest request, HttpServletResponse response) throws IOException {
    	ajaxList(model, request, response);//ajax yemian 
    }
    /**
     * 跳转到导入页
     * @param model 模型
     * @return 返回导入页
     */
    @RequestMapping(value = "import", method = RequestMethod.GET)
    public String importDataForm(Model model) {
        return "/qb5activiti/base/price/importPrice";
    }
    
    /**
     * 执行导入
     * @param model 模型
     * @return 返回导入页面
     */
    @RequestMapping(value = "import", method = RequestMethod.POST)
    public String importData(Model model) {
        model.addAttribute("isSubmit", "1");
        return "/qb5activiti/base/price/importPrice";
    }
    
    /**
     * 定制导出
     * @param model 模型
     * @return 返回导出页面
     */
    @RequestMapping(value = "export", method = RequestMethod.GET)
    public String exportCustomForm(Model model) {
        return "/qb5activiti/base/price/exportPrice_custom";
    }
    
    /**
     * 执行导出
     * @param model 模型
     * @return 返回导出xls页面
     */
    @RequestMapping(value = "export", method = RequestMethod.POST)
    public String exportData(Model model) {
        return "/qb5activiti/base/price/exportPrice_excel";
    }

    /**
     * 从request中获得查询条件
     * @param request http请求对象
     * @return 条件Map
     */
    public static Map<String, Object> getQueryCondition(HttpServletRequest request) {
        Map<String, Object> searchMap = null;
        if(request.getAttribute(REQUEST_QUERY_CONDITION) != null) {  //如果request.getAttribute中有，就不取request.getParameter
            searchMap = (Map<String, Object>)request.getAttribute(REQUEST_QUERY_CONDITION);
        } else {
           searchMap = new HashMap<String, Object>();
           searchMap.put("id", request.getParameter("id"));
           searchMap.put("productId", request.getParameter("productId"));
           searchMap.put("productName", request.getParameter("productName"));
           searchMap.put("productLevel", request.getParameter("productLevel"));
           searchMap.put("levelCode", request.getParameter("levelCode"));
           searchMap.put("price", request.getParameter("price"));
           searchMap.put("startTime", request.getParameter("startTime"));
           searchMap.put("endTime", request.getParameter("endTime"));
           searchMap.put("status", request.getParameter("status"));
           searchMap.put("delete_flag",ISystemConstant.DICTIONARY_RM_YES_NOT_0);
        }
        return searchMap;
    }
   /**
     * 详情页
     * 
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value="toDetail")
    public String toDetail(Model model, HttpServletRequest request){    	
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

	    	String id=request.getParameter("id");
    	
	    	PriceVo vo=priceService.get(id);
    	
    		model.addAttribute("priceVo", vo);
    	
	    	model.addAttribute("id", id);    
    		return "/qb5activiti/base/price/detailPrice";  
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }  	
    }
   /**
    * 导出通用业务表数据为xls,并下载
    * @throws Exception 
    *
    */
    @RequestMapping(value="exportXls"+ISystemConstant.SUFFIX_ACTION)
    public void frontExportXls(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception{	
          exportXls(model, request, response);
    }
   /**
    * 导出通用业务表数据为xls,并下载
    * @throws Exception 
    **/
   @RequestMapping(value="exportXls")
   public void backExportXls(Model model,HttpServletRequest request,HttpServletResponse response) throws Exception{	
          exportXls(model, request, response);
   }
   /**
    * 导出xls公共方法
    * @param model
    * @param request
    * @param response
    * @throws UnsupportedEncodingException
    */
   private void exportXls(Model model, HttpServletRequest request,
		HttpServletResponse response) throws UnsupportedEncodingException {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

	    	//获取排序
	    	String order = request.getParameter(ISystemConstant.PREDEFINED_ORDER);
	    	if(!StringHelper.isEmpty(order)){
			String order1 = new String(order.getBytes("ISO-8859-1"),"UTF-8");
		    	order = java.net.URLDecoder.decode(order1, "UTF-8");
	    	}
	    	Map<String, Object> searchPara = new HashMap<String,Object>();
	    	searchPara.put("delete_flag",ISystemConstant.DICTIONARY_RM_YES_NOT_0);
	    	List<PriceVo> vos = priceService.list(searchPara, order);    		
	    	String sheetName = request.getParameter(ISystemConstant.PREDEFINED_SHELL_NAME);
	    	if(StringHelper.isEmpty(sheetName)){
	    		sheetName = ISystemConstant.DEFAULT_SHELL_NAME;
	    	}
	    	LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String,String>();
	    	//获取删除的列名
	    	String deletes = request.getParameter(ISystemConstant.PREDEFINED_EXPORT_DELETE_COLUMNNAMES);
	    	List<String> deleteList =  new ArrayList<String>();
	    	if(!StringHelper.isEmpty(deletes)){
	    		deleteList = Arrays.asList(deletes.split(","));
	    	}
	    	//所有字段放入fieldMap
	    	fieldMap.put("id","ID");
	    	fieldMap.put("productId","产品ID");
	    	fieldMap.put("productName","产品名称");
	    	fieldMap.put("productLevel","产品等级");
	    	fieldMap.put("levelCode","等级编码");
	    	fieldMap.put("price","执行价格");
	    	fieldMap.put("startTime","开始时间");
	    	fieldMap.put("endTime","结束时间");
	    	fieldMap.put("status","状态");
	    	//删除无用字段
	    	for(String  propertyName:deleteList){
	    	    if(fieldMap.containsKey(propertyName)){
	    		fieldMap.remove(propertyName);
	    		continue;
	    	    }
	    	}
	    	
	    	//获取需要隐藏的列数组
	    	String hides = request.getParameter(ISystemConstant.PREDEFINED_EXPORT_HIDE_COLUMNNAMES);
	    	
	    	List<String> hideList =  new ArrayList<String>();
	    	if(!StringHelper.isEmpty(hides)){
	    		hideList = Arrays.asList(hides.split(","));
	    	}
	    	ExcelService.listToExcel(vos, fieldMap, hideList,sheetName, response);		
          }finally{
	    	//最后解锁
	    	RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * 前台导入通用业务表数据为xls到数据库
     * @throws Exception 
     **/
    @RequestMapping(value="importXls"+ISystemConstant.SUFFIX_ACTION)
    public void frontImportXls(HttpServletRequest request, HttpServletResponse response) throws Exception{
    	importXls(request, response);
    }
    /**
     * 后台导入通用业务表数据为xls到数据库
     * @throws Exception 
     **/
    @RequestMapping(value="importXls")
    public void backImportXls(HttpServletRequest request, HttpServletResponse response) throws Exception{
    	importXls(request, response);
    }
    /**
     * 导入xls公共方法
     * @param request
     * @param response
     */
    private void importXls(HttpServletRequest request, HttpServletResponse response) {
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));

		   try {
			//获取上传文件xls
			List<MultipartFile> uploadFiles = FileOperateHelper.listMultipartFile(request);
			if(uploadFiles==null ||uploadFiles.isEmpty()){
				throw new PjException("缺少上传文件!");
			}	
			String sheetName = request.getParameter(ISystemConstant.PREDEFINED_SHELL_NAME);
			if(StringHelper.isEmpty(sheetName)){
		    		sheetName = ISystemConstant.DEFAULT_SHELL_NAME;
			}
			LinkedHashMap<String,String> fieldMap = new LinkedHashMap<String,String>();
			String idCnName=null;//id中文名

			idCnName ="ID";
			fieldMap.put("ID","id");
			fieldMap.put("产品ID","productId");
			fieldMap.put("产品名称","productName");
			fieldMap.put("产品等级","productLevel");
			fieldMap.put("等级编码","levelCode");
			fieldMap.put("执行价格","price");
			fieldMap.put("开始时间","startTime");
			fieldMap.put("结束时间","endTime");
			fieldMap.put("状态","status");

			MultipartFile mfile = uploadFiles.get(0);
		    	
			List<PriceVo> vos =null;
			InputStream inputStream = null;
			try{
				inputStream = mfile.getInputStream();
				if(!StringHelper.isEmpty(idCnName)){
					vos = ExcelService.excelToList(inputStream, sheetName, PriceVo.class, fieldMap, new String[]{idCnName});
				}else{
					vos = ExcelService.excelToList(inputStream, sheetName, PriceVo.class, fieldMap, new String[]{});
				}
			}finally{
				if(inputStream!=null){
					inputStream.close();
					inputStream = null;
				}
			}
			priceService.insertUpdateBatch(vos); 
			
		   } catch (Exception e) {
			e.printStackTrace();
			Map<String, Object> result = new HashMap<String, Object>();//
			result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_FAIL);
			String PjException = "com.dfhc.PjException:";
			result.put(ISystemConstant.AJAX_MESSAGE, e.getMessage().substring(e.getMessage().indexOf(PjException)+PjException.length()));
			response.setContentType("text/html;charset=utf-8");
			try {
				response.getWriter().print(JSONObject.toJSONString(result));
				response.getWriter().flush();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			return;
		   }
		   Map<String, Object> result = new HashMap<String, Object>();
		   result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
		   result.put(ISystemConstant.AJAX_MESSAGE, "导入成功!");
		   response.setContentType("text/html;charset=utf-8");
		   try {
			response.getWriter().print(JSONObject.toJSONString(result));
			response.getWriter().flush();
		   } catch (IOException e) {
			e.printStackTrace();
		   }
          }finally{
		   //最后解锁
		   RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * ajax逻辑删除
     * @param request http请求对象
     * @param redirectAttributes 重定向属性
     * @return 返回列表页面
    */
    @RequestMapping(value = "ajaxLogicDelete", method = RequestMethod.POST, 
    consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String, Object> ajaxLogicDelete(HttpServletRequest request) {
          Map<String, Object> result = new HashMap<String, Object>();
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));


	        String id = request.getParameter(REQUEST_ID);
        	if(id != null && id.length() > 0) {
	            priceService.deleteLogic(request,id);
        	} else {
	            String[] ids = RmJspHelper.getArrayFromRequest(request, REQUEST_IDS); //从request获取多条记录id
        	    if (ids != null && ids.length != 0) {
                	priceService.deleteLogic(request,ids);  //删除多条记录
	            }
        	}
        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
        	result.put(ISystemConstant.AJAX_MESSAGE, "删除成功!");
        	return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    /**
     * ajax删除
     * @param request http请求对象
     * @param redirectAttributes 重定向属性
     * @return 返回列表页面
    */
    @RequestMapping(value = "ajaxDelete", method = RequestMethod.POST, 
    consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String, Object> ajaxDelete(HttpServletRequest request) {
          Map<String, Object> result = new HashMap<String, Object>();
          boolean bLock = false;
          try{
	    	bLock = RequestConcurrentRoute.getSingleton().lock(request.getParameter(ISystemConstant.JSGUID));


	        String id = request.getParameter(REQUEST_ID);
        	if(id != null && id.length() > 0) {
	            priceService.delete(id);
        	}
        	result.put(ISystemConstant.AJAX_STATUS, ISystemConstant.AJAX_RESULT_SUCCESS);
        	result.put(ISystemConstant.AJAX_MESSAGE, "删除成功!");
        	return result;
          }finally{
    		//最后解锁
    		RequestConcurrentRoute.getSingleton().unLock(request.getParameter(ISystemConstant.JSGUID),bLock);
          }
    }
    
  
    
}
